﻿using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            Uri tfsUri = new Uri("http://mywebsite:8080/tfs/DefaultCollection");
            TfsTeamProjectCollection projectCollection = new TfsTeamProjectCollection(tfsUri);
            WorkItemStore workItemStore = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));

            sb.AppendLine("Id,Title,Assigned To");

            WorkItemCollection queryResults = workItemStore.Query(@"
                Select  [ID],[title] 
                From WorkItems
                Where [Outcome] = 'Done' and [Team Project] = 'MyProject'");
            foreach (WorkItem item in queryResults)
            {
                //item.Open();
                //item.Fields["Outcome"].Value = "Ready for test";
                sb.AppendLine(item.Id + "," + item.Title + "," + item.Fields["Assigned To"].Value);

                //item.Save();
            }

            Console.WriteLine(sb.ToString());

        }
    }
}
